package com.example.demo.service.Impl;


import com.example.demo.bean.Interfaces;
import com.example.demo.bean.InterfacesExample;
import com.example.demo.dao.InterfacesMapper;
import com.example.demo.service.IInterfacesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class InterfacesServiceImpl implements IInterfacesService {

    @Resource
    private InterfacesMapper interfacesMapper;

    @Override
    public List<Interfaces>query(Long id,String name){
        InterfacesExample example= new InterfacesExample();
       if (!StringUtils.isEmpty(id)){
           example.createCriteria().andIdEqualTo(id);
       }
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }
    List<Interfaces>list=interfacesMapper.selectByExample(example);
    return list;
}

@Override
public void saveOrUpdate(Interfaces interfaces){
    if(interfaces.getId()==null){
        interfacesMapper.insert(interfaces);
    }else {
        interfacesMapper.updateByPrimaryKey(interfaces);
    }
}

@Override
public void deleteById(Long id ) {
   interfacesMapper.deleteByPrimaryKey(id);
    }
}